package FlowGram.Application.CommandHost;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.text.html.parser.Parser;

import FlowGram.Application.Application;
import FlowGram.Application.CommandHost.FinchActionListeners.FinchActionListener;
import FlowGram.Application.IDEWindow.MainWindow;
import FlowGram.Application.IDEWindow.FileHost.CodeEditor;
import FlowGram.Application.IDEWindow.FileHost.FlowEditor;
import FlowGram.Application.Parser.FinchParser;
import FlowGram.Application.Parser.Actions.BeakColor;
import FlowGram.Application.Parser.Actions.Chirp;
import FlowGram.Application.Parser.Actions.FinchAction;
import FlowGram.Application.Parser.Actions.Move;
import FlowGram.Application.Parser.Actions.TurnLeft;
import FlowGram.Application.Parser.Actions.TurnRight;
import FlowGram.Application.Parser.Actions.Control.FunctionDefinition;
import FlowGram.Application.Parser.Actions.Control.If;
import FlowGram.Application.Parser.Actions.Control.Repeat;
import FlowGram.Application.Parser.Actions.Control.While;


public class CommandItem extends JButton implements ActionListener {
	private String name;			//name displayed
	private String actionName;		//used to check with the actions inside the programFlow
	private String category;			//labels like �primitives� �properties� �macros�
	private String syntax;
	private FinchAction fa;
	
	public CommandItem(String finchAction, String category){
		super(finchAction);
		
		name = finchAction;
		if(finchAction.equals("Move")){
			fa = new Move();
			syntax = Move.syntax();
		}else if(finchAction.equals("TurnLeft")){
			fa = new TurnLeft();
			syntax = TurnLeft.syntax();
		}else if(finchAction.equals("TurnRight")){
			fa = new TurnRight();
			syntax = TurnRight.syntax();
		}else if(finchAction.equals("While")){
			syntax = While.syntax();
		}else if(finchAction.equals("Repeat")){
			syntax = Repeat.syntax();
		}else if(finchAction.equals("If")){
			syntax = If.syntax();
		}else if(finchAction.equals("FunctionDefinition")){
			syntax = FunctionDefinition.syntax();
		}else if(finchAction.equals("Chirp")){
			syntax = Chirp.syntax();
		}else if(finchAction.equals("BeakColor")){
			syntax = BeakColor.syntax();
		}
		
		this.category = category;
		
	}

	public String getName(){
		return name;
	}
	
	public String getCategory(){
		return category;
	}
	
	public String toString(){
		return "(<" + name + ">,<" + category + ">)";
	}
	
	public void actionPerformed(ActionEvent e){
		System.out.println(name + "clicked");
		if(category.equals("Actions")){
			if(!name.equals("FunctionInvocation")){
				FinchActionListener.addCode(fa);
			}
		}else if(category.equals("Control")){
			//individual action listeners will handle event
		}
		
	}
	
	
}
